﻿<UserControl x:Class="TanmiaGrp.GeneralLedger.WinApp.Scenarios.AccountEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:loc="clr-namespace:TanmiaGrp.GeneralLedger.WinApp"
             xmlns:Scenarios="clr-namespace:TanmiaGrp.GeneralLedger.WinApp.Scenarios"  
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             mc:Ignorable="d"
             d:DesignHeight="600"
             d:DesignWidth="650"
             FlowDirection="RightToLeft">
    <UserControl.Resources>
        <loc:NullToVisibilityConverter x:Key="nullConverter" />
        <loc:IsTransactionalConverter x:Key="isTransactionalConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!-- Header -->
        <DockPanel Grid.Row="0" Height="46">
            <Scenarios:WindowBar x:Name="windowBar" DockPanel.Dock="Left" PopouClicked="OnPopout" />
            <TextBlock Style="{StaticResource CaptionStyle}" 
                       Text="{Binding Path=StateText}" />
            <TextBlock DockPanel.Dock="Left" 
                       Text="حساب" 
                       Style="{StaticResource CaptionStyle}"  />

            <Scenarios:NewBar HorizontalAlignment="Right" DockPanel.Dock="Right" />
            <Scenarios:SaveBar HorizontalAlignment="Right" />
        </DockPanel>

        <Grid Grid.Row="1">
            <Grid.Resources>
                <Style TargetType="HeaderedContentControl">
                    <Setter Property="Foreground" Value="#ff6e6e6e" />
                    <Setter Property="Focusable" Value="False" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="HeaderedContentControl">
                                <StackPanel Margin="0,0,0,2">
                                    <ContentPresenter ContentSource="Header" Margin="6,0,6,4" />
                                    <ContentPresenter ContentSource="Content" Margin="7,4,7,4" />
                                </StackPanel>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="193" Width="1*" />
                <ColumnDefinition MinWidth="5" Width="5" />
                <ColumnDefinition MinWidth="125" Width="1*" />
                <ColumnDefinition MinWidth="125" Width="1*" />
                <ColumnDefinition MinWidth="125" Width="1*" />
                <ColumnDefinition MinWidth="125" Width="1*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <!--<HeaderedContentControl Header="رقم تعريف الحساب">
                <TextBox Text="{Binding Path=Entity.AccountID}"
                                 IsReadOnly="True" />
            </HeaderedContentControl>-->

            <HeaderedContentControl Grid.Row="0" Grid.Column="2" Header="رقم الحساب">
                <TextBox Height="30"
                         VerticalContentAlignment="Center"
                         Text="{Binding Path=Entity.AccountNumber, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" Header="اسم الحساب">
                <TextBox Height="30" 
                         VerticalContentAlignment="Center"
                         Text="{Binding Path=Entity.AccountName, ValidatesOnDataErrors=True, NotifyOnSourceUpdated=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  />
            </HeaderedContentControl>

            <!--<HeaderedContentControl Header="مستوى الحساب">
                <TextBox Text="{Binding Path=Entity.Level}" />
            </HeaderedContentControl>-->

            <HeaderedContentControl Grid.Row="1" Grid.Column="2" Header="طبيعة الحساب">
                <ComboBox Height="30"
                          VerticalContentAlignment="Center"
                          SelectedIndex="{Binding Path=Entity.IsTransactional, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource isTransactionalConverter}}">
                    <ComboBoxItem>رئيسي</ComboBoxItem>
                    <ComboBoxItem>فرعي</ComboBoxItem>
                </ComboBox>
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="1" Grid.Column="3" VerticalAlignment="Bottom">
                <CheckBox Height="30" 
                          BorderBrush="#53a0cc" 
                          BorderThickness="2" 
                          Foreground="#ff6e6e6e" 
                          Content="ختامي ؟" 
                          IsChecked="{Binding Path=Entity.IsFinal, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="1" Grid.Column="4" VerticalAlignment="Bottom">
                <CheckBox Height="30" 
                          BorderBrush="#53a0cc"
                          BorderThickness="2"
                          Foreground="#ff6e6e6e" 
                          Content="مفعل ؟" 
                          IsChecked="{Binding Path=Entity.IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="2" Grid.Column="2">
                <CheckBox Height="30" 
                          BorderBrush="#53a0cc"
                          BorderThickness="2"
                          Foreground="#ff6e6e6e" 
                          Content="قبول الحركات المدينة" IsChecked="{Binding Path=Entity.IsDebitable, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="2" Grid.Column="3">
                <CheckBox Height="30" 
                          BorderBrush="#53a0cc"
                          BorderThickness="2"
                          Foreground="#ff6e6e6e" 
                          Content="قبول الحركات الدائنة" IsChecked="{Binding Path=Entity.IsCreditable, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="2" Grid.Column="4">
                <CheckBox Height="30" 
                          BorderBrush="#53a0cc"
                          BorderThickness="2"
                          Foreground="#ff6e6e6e" 
                          Content="قبول الحركات النقدية" IsChecked="{Binding Path=Entity.IsCashable, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>

            <!--<HeaderedContentControl Header="قبول الشيكات">
                <CheckBox IsChecked="{Binding Path=Entity.IsCheckable, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>-->

            <HeaderedContentControl Grid.Row="3" Grid.Column="2" Header="الحد الأعلى الدائن">
                <TextBox Height="30"
                         VerticalContentAlignment="Center"
                         Text="{Binding Path=Entity.MaxDebit, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="3" Grid.Column="3" Header="الحد الأعلى المدين">
                <TextBox Height="30"
                         VerticalContentAlignment="Center"
                         Text="{Binding Path=Entity.MaxCredit, ValidatesOnDataErrors=True, NotifyOnSourceUpdated=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="4" Grid.Column="2" Header="تاريخ إنشاء الحساب">
                <DatePicker Height="30"
                            VerticalContentAlignment="Center"
                            Foreground="#ff6e6e6e" 
                            SelectedDate="{Binding Path=Entity.CreateDate, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="4" Grid.Column="3" Header="تاريخ آخر تعديل">
                <TextBox Height="30"
                         VerticalContentAlignment="Center" 
                         Text="{Binding Path=Entity.LastUpdateDate}"
                         IsReadOnly="True" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="5" Grid.Column="2" Header="مجموع المدين">
                <TextBox Height="30" 
                         VerticalContentAlignment="Center"
                         Text="{Binding Path=Entity.TotalDebit}"
                         IsReadOnly="True" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="5" Grid.Column="3" Header="مجموع الدائن">
                <TextBox Height="30" 
                         VerticalContentAlignment="Center"
                         Text="{Binding Path=Entity.TotalCredit}"
                         IsReadOnly="True" />
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="5" Grid.Column="4" Header="الرصيد">
                <TextBox Height="30" 
                         VerticalContentAlignment="Center"
                         Text="{Binding Path=Entity.Balance}"
                         IsReadOnly="True" />
            </HeaderedContentControl>


            <Border Grid.Row="0" Grid.RowSpan="6" Grid.Column="1" Width="1" Margin="2,0">
                <Border.Background>
                    <LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
                        <GradientStop Color="#FFDADADA" Offset="0.0" />
                        <GradientStop Color="#919191" Offset=".8" />
                        <GradientStop Color="#919191" Offset=".2" />
                        <GradientStop Color="#FFE4E4E4" Offset="1.0" />
                    </LinearGradientBrush>
                </Border.Background>
                <Border.Effect>
                    <DropShadowEffect ShadowDepth="0" Direction="1" Opacity="0.395" Color="#FF919191"  />
                </Border.Effect>
            </Border>

            <HeaderedContentControl Grid.Row="0" Grid.Column="0" Header="حساب الأب">
                <ComboBox Height="30"
                          VerticalContentAlignment="Center"
                          ItemsSource="{Binding Path=ParentAccounts}"
                          SelectedValuePath="AccountID"
                          SelectedItem="{Binding Path=Entity.Parent, ValidatesOnDataErrors=True, NotifyOnSourceUpdated=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                          SelectedValue="{Binding Path=Entity.ParentAccountID, Mode=OneWayToSource}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="80" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>

                                <TextBlock Text="{Binding Path=AccountNumber}"
                                                   Grid.Column="0" />

                                <TextBlock Text="{Binding Path=AccountName}"
                                                   Grid.Column="1" />
                            </Grid>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>

                </ComboBox>
            </HeaderedContentControl>

            <HeaderedContentControl Grid.Row="1" Grid.RowSpan="5" Grid.Column="0" Header="المجموعات" VerticalContentAlignment="Stretch" VerticalAlignment="Stretch">
                <Grid VerticalAlignment="Stretch">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <ComboBox Name="cmbGroups" 
                              Grid.Row="0"
                              Height="30"
                              ItemsSource="{Binding Path=Groups}"
                              DisplayMemberPath="GroupName" />

                    <Button Grid.Column="1" Width="30" Height="30" Margin="4,0,0,0" Padding="0" ToolTip="إضافة المجموعة" Click="AddGroupHandler">
                        <Path Data="{StaticResource Add}" 
                                      Fill="DeepSkyBlue"
                                      Stretch="Uniform"
                                      Height="24"/>
                    </Button>

                    <ListBox Name="lbAccountGroups"
                             Grid.Row="1" Grid.ColumnSpan="2"
                             Margin="0,4,0,0"
                             VerticalAlignment="Stretch"
                             HorizontalContentAlignment="Stretch"
                             Height="200"
                             ItemsSource="{Binding Path=Entity.AccountGroups, ValidatesOnDataErrors=True, NotifyOnSourceUpdated=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             MouseDoubleClick="lbAccountGroups_MouseDoubleClick_1" BorderThickness="1"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                            </Style>
                        </ListBox.ItemContainerStyle>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="#f1f1f1" BorderThickness="0,1,0,0">
                                    <Grid Margin="7">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>

                                        <TextBlock Text="{Binding Path=GroupName}" Foreground="#333333" />
                                        <TextBlock Grid.Row="1" Text="{Binding Path=Notes}" Foreground="#999999" TextTrimming="CharacterEllipsis" />

                                        <Border Grid.Column="1" 
                                                Grid.RowSpan="2"
                                                ToolTip="إنقر بشكل مزدوج ليتم حذف المجموعة"
                                                Background="Transparent">
                                            <Path Fill="DeepSkyBlue"
                                                  Stretch="Uniform"
                                                  Width="16"
                                                  Data="{StaticResource Remove}" />
                                        </Border>
                                    </Grid>
                                </Border>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>

            </HeaderedContentControl>

        </Grid>

        <!-- Footer -->
        <DockPanel Grid.Row="2" Height="46">
            <Scenarios:DeleteBar />
            <Scenarios:EntityNavigationBar HorizontalAlignment="Right" DockPanel.Dock="Right" />
        </DockPanel>
        <!--<Label Content="إذا أردت إنشاء مجموعة جديدة\r\nقم بالضغط على زر جديد أولا."
                   VerticalContentAlignment="Center"
                   HorizontalContentAlignment="Center"
                   Background="White"
                   Opacity=".7"
                   Visibility="{Binding Path=Entity, Converter={StaticResource nullConverter}, ConverterParameter=NOT}" />-->
    </Grid>
</UserControl>
